package com.CST.controller.cb;

import com.CST.common.api.Response;
import com.CST.common.api.ResultObject;
import com.CST.dto.cb.DateDTO;
import com.CST.entity.cb.JxCost;
import com.CST.entity.cb.JxObjectiveAssessment;
import com.CST.service.cb.JxObjectiveAssessmentService;
import com.CST.vo.cb.JXInComeVO;
import com.CST.vo.cb.JxObjectiveAssessmentVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.concurrent.ExecutionException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author qtx
 * @since 2023-05-24
 */
@Api(tags={"绩效年度考核实际表"})
@RestController
@RequestMapping("/jxObjectiveAssessment")
public class JxObjectiveAssessmentController {
    @Autowired
    private JxObjectiveAssessmentService service;

    @ApiOperation("修改")
    @PostMapping("/modifyPerformance")
    public ResultObject modifyPerformance(@RequestBody JxObjectiveAssessment jxObjectiveAssessment) {
        Response response = service.modifyJxObjectiveAssessment(jxObjectiveAssessment);
        return ResultObject.resultReturn(response);
    }


    @ApiOperation("导入")
    @PostMapping("/importExcelJxObjectiveAssessment")
    public ResultObject importExcelJxObjectiveAssessment(MultipartFile file,  @RequestParam("year") Integer year) throws Exception {
        try {
            service.importExcelJxObjectiveAssessment(file,year);
        } catch (Exception e) {
            throw new Exception("导入失败");
        }
        return ResultObject.successReturn("导入成功");

    }
    @ApiOperation("查询绩效得分表")
    @PostMapping("/queryByYear")
    public ResultObject queryByYear(@RequestBody DateDTO dateDTO) throws ExecutionException, InterruptedException {
        List<JxObjectiveAssessmentVO> jxObjectiveAssessmentVOList = service.queryByYear(dateDTO);
        return ResultObject.success(jxObjectiveAssessmentVOList);
    }

    @ApiOperation("导出模板")
    @PostMapping("/exportExcelJxObjectiveAssessmentDemo")
    public void exportExcelJxObjectiveAssessmentDemo(HttpServletResponse response) {
        service.exportExcelJxObjectiveAssessmentDemo(response);
    }
    @ApiOperation("导出")
    @PostMapping("/exportExcelJxObjectiveAssessment")
    public void exportExcelJxObjectiveAssessment(HttpServletResponse response, @RequestBody DateDTO dateDTO) throws ExecutionException, InterruptedException {
        service.exportExcelJxObjectiveAssessment(response, dateDTO);
    }

}
